package org.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Predicate;

public class Function_Demo2 {
    public  static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张三","张守元","王行之","张由心");
        list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.startsWith("张")&&s.length()==3;
            }
        }).forEach(s-> System.out.println(s));
        System.out.println("----------------");
        //静态方法中没有this 。调用方法需要创建对象来调用 创建本类对象来调用
        //对象::方法名 this::方法 ->本类 super::方法 ->父类
        list.stream().filter(new Function_Demo2() ::check).forEach(System.out::println);
    }
    public boolean check(String s){
        return s.startsWith("张")&&s.length()==3;
    }
}
